<template>

  <div class="evaluation-management views-container">
    <el-dialog title="注意" :visible.sync="dialogFormVisible">
  <el-form :model="replyMsg">
    <el-form-item label="回复内容" :label-width="formLabelWidth">
      <el-input v-model="replyMsg.content" autocomplete="off"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="quebtn">确 定</el-button>
  </div>
</el-dialog>
    <div class="wlm-table">
      <div class="wlm-table-hearder-btn">
        <router-link tag="span" to="/merchandise/evaluationManagementAdd">
          <el-button size="small" type="primary">添加评论</el-button>
        </router-link>
      </div>
      <div class="wlm-table-header">
        <el-form :model="tableFormatData.announcement.files" size="small" label-width="82px" class="retail-form" label-position="right">
          <el-form-item label="" class="filter">
            <el-form-item label="用户：">
              <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.announcement.files.nickName" placeholder="请输入用户昵称" style="width:200px;"></el-input>
            </el-form-item>
            <el-form-item label="商品名称：">
              <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.announcement.files.goods_name" placeholder="请输入商品名称" style="width:200px;"></el-input>
            </el-form-item>
          </el-form-item>
          <el-form-item label="" class="filter">
            <el-form-item label="评论等级：">
              <el-select v-model="tableFormatData.announcement.files.score" placeholder="请选择" style="width:200px;">
                <el-option :label="'好评'" :value="3">
                </el-option>
                <el-option :label="'中评'" :value="2">
                </el-option>
                <el-option :label="'差评'" :value="1">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="评论来源：">
              <el-select v-model="tableFormatData.announcement.files.source" placeholder="请选择" style="width:200px;">
                <el-option :label="'微信小程序'" :value="'2'">
                </el-option>
                <el-option :label="'H5'" :value="'3'">
                </el-option>
                <el-option :label="'微信公众号'" :value="'4'">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form-item>
          <el-form-item label="" class="filter-btns">
            <el-button type="primary" @click="filesSerch">筛选</el-button>
            <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
          </el-form-item>
        </el-form>
      </div>

      <div class="wlm-table-content">
        <el-tabs v-model="tableFormatData.announcement.files.status" type="card" @tab-click="filesSerch">
          <!-- @tab-click="filesSerch" -->
          <el-tab-pane label="全部评论" name="all"></el-tab-pane>
          <el-tab-pane label="待回复" name="1"></el-tab-pane>
          <el-tab-pane label="已回复" name="2"></el-tab-pane>
        </el-tabs>
        <el-table :ref="tableFormatData.announcement.key" :data="tableFormatData.announcement.tableData" @selection-change="handleSelectionChange" style="width: 100%">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column prop="date" label="用户">
            <template slot-scope="scope">
              <p>{{scope.row.nickName}}</p>
              <p>ID:{{scope.row.user_id}}</p>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="商品名称">
            <template slot-scope="scope">
              <span>{{scope.row.goods_name}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="状态">
            <template slot-scope="scope">
              <span>{{scope.row.status ? '显示' :'隐藏'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="评论等级">
            <template slot-scope="scope">
              <el-rate disabled v-model="scope.row.score" :colors="['#99A9BF', '#F7BA2A', '#FF9900']">
              </el-rate>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="评论来源">
            <template slot-scope="scope">
              <span>{{sourceType[`${scope.row.source || '-'}`]}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="评论时间">
            <template slot-scope="scope">
              <span>{{scope.row.create_time}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="date" label="显示">
            <template slot-scope="scope">
              <el-switch :active-value="1" :inactive-value="0" @change="changeTableItem({comment_id:scope.row.comment_id,status:scope.row.status},tableFormatData.announcement.change.status,{cancel:{msg:'已取消关闭',val:{scope:scope,cancelStatus:{key:'status',val:1}}}})" v-model="scope.row.status"> </el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="address" label="操作">
            <template slot-scope="scope">
              <div class="operation-group">
                <router-link class="wlm-text" tag="span" :to="{path:'/merchandise/evaluationManagementDetail', query:{comment_id:scope.row.comment_id}}">
                  <el-button type="text">查看</el-button>
                </router-link>
                <div class="btn-line"></div>
                <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.comment_id)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-b flex-align-c">
          <el-row class="pagination-btns">
            <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.announcement.files.checkall" @change="toggleSelection">全部</el-checkbox>
            <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">批量删除</el-button>
            <!-- <el-button
class="right-8"
:disabled="isGroup"
type="primary"
size="mini"
            @click="changeTableItem(replyMsg,tableFormatData.announcement.change.reply,
            {isWarning: true,warning:$createElement('p', null, [$createElement('p', null, ['回复内容',$createElement('el-input', {style: {width:'120px','margin-left':'10px'},
            nativeOn: {'change': updateMsg},props:{size:'small',value:`${replyMsg.content}`}})])]),cancel:'已取消'})">批量回复</el-button> -->
            <el-button
class="right-8"
:disabled="isGroup"
type="primary"
size="mini"
            @click="changeTable">批量回复</el-button>
          </el-row>
          <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.announcement.pagination.page" :page-sizes="tableFormatData.announcement.pagination.pagesizes" :page-size.sync="tableFormatData.announcement.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.announcement.pagination.total : 0">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getCommentList,
  delComment,
  setCommentShow,
  replyComment
} from '@/api/merchandise'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'EvaluationManagement',
  components: {

  },
  data() {
    return {
      dialogFormVisible: false,
      formLabelWidth: '120px',
      replyMsg: {
        isGroup: true,
        content: ''
      },
      sourceType: {
        '1': '导入',
        '2': '微信小程序',
        '3': 'H5',
        '4': '公众号',
        '5': '安卓',
        '6': '苹果',
        '7': '支付宝小程序',
        '8': '百度小程序',
        '9': '头条小程序',
        '-': '-'
      },
      tableFormatData: {
        current: 'announcement',
        announcement: {
          key: 'announcement',
          api: {
            getList: getCommentList,
            delList: delComment
          },
          tableData: [],
          files: {
            nickName: '',
            goods_name: '',
            score: '',
            source: '',
            status: 'all',
            ids: [],
            redirect: 'comment_id',
            checkall: '0',
            Recycle: '0'
          },
          change: {
            status: {
              name: '编辑',
              key: 'status',
              api: setCommentShow
            },
            reply: {
              name: '回复',
              key: 'reply',
              api: replyComment
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    updateMsg(event) {
      console.log('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh', event)
      const { target: { value = '' } } = event
      this.replyMsg.content = value
    },
    changeTable(event) {
      this.dialogFormVisible = true
    },
    quebtn() {
      this.dialogFormVisible = false
      var array = []
      this.tableFormatData.announcement.files.ids.map(res => {
        console.log('resssssssssssssssssss', res.comment_id)
        if (res.status == 1) {
          array.push(res.comment_id)
        }
      })
      replyComment({ content: this.replyMsg.content, ids: array }).then(res => {
        const { data: { code, msg } } = res
        if (code == 1) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.filesEmpty()
        } else {
          this.$message.error(msg)
        }
      })
    }
    // changeTable(event){
    //   console.log(11111111111111)
    //   this.dialogFormVisible=true
    // },
    // quebtn(){
    //   this.dialogFormVisible = false
    //   console.log("dddddddddddddddddddd",this.tableFormatData.announcement.files.checkall)
    //   replyComment().then(res=>{
    //     console,log('sdddddddddddddddddddddddddd',res)
    //   })
    // }
  }
}
</script>

<style lang="scss" scoped>
.evaluation-management {
  .logo {
    height: 32px;
    width: 32px;
    border-radius: 32px;
    vertical-align: middle;
  }

  & .orders-red {
    color: rgb(245, 108, 108);
  }
}
</style>
